<!DOCTYPE html>
<html>
<head>
    <title>录入住院信息--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="../Css/style.css"/>
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>
    <script type="text/javascript" src="../Js/ckeditor/ckeditor.js"></script>


    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
    <script type="text/javascript">
        $(function () {
            $('#backid').click(function () {
                window.location.href = "index.html";
            });
        });

        //获取挂号信息
        function getMsg() {
            let hosrObj = $("input[name='hosrId']");
            let hosrId = hosrObj.val();
            if (isNaN(hosrId)) {
                alert("请输入数字")
                hosrObj.val("")
                return;
            }
            //发送ajax请求
            $.ajax({
                url: "selectBeHospitalStateById",
                data: {'hosrId': hosrId},
                type: 'get',
                dataType: 'json',
                success: function (data) {
                    let rig = data.data.totalMsg;

                    if(data.data.totalMsg == null || data.data.totalMsg == ''){
                        console.log("sdsdsd")
                        alert("该挂号id不存在");
                        hosrObj.val("");
                        return ;
                    }

                    if (rig.primaryStatus==1){
                        alert("该挂号id已住院，请重新输入");
                        hosrObj.val("");
                        return ;
                    }

                    if (rig.primaryStatus==2){
                        alert("该挂号id已退号");
                        hosrObj.val("");
                        return ;
                    }
                    //挂号信息回显数据
                    //$("input[name='hosrId']").val(rig.hosrId);
                    $("input[name='hosrSelfprice']").val(rig.hosrSelfprice);
                    $("input[name='hosrSex']").val(rig.hosrSex);
                    $("input[name='hosrLookdoctor']").val(rig.hosrLookdoctor);
                    $("#hosrName").text(rig.hosrName);
                    $("#hosrIdcar").text(rig.hosrIdcar);
                    $("#hosrMedical").text(rig.hosrMedical);
                    $("#hosrPhone").text(rig.hosrPhone);
                    $("#hosrAge").text(rig.hosrAge);
                    $("#hosrRemark").text(rig.hosrRemark);

                    //是否自费数据回显
                    feiSelf(rig.hosrSelfprice);

                    //性别数据回显
                    sexXian(rig.dSex);

                    //初复珍数据回显
                    fuZhen(rig.dSex)

                    getDoctor();
                }
            });
        }

        function fuZhen(data){
            //初复珍数据回显
            if (data==1){
                $("input[name='hosrLookdoctor'][value='1']").attr("checked","checked");
            }else {
                $("input[name='hosrLookdoctor'][value='0']").attr("checked","checked");
            }
        }

        function feiSelf(data){
            //是否自费数据回显
            if (data==1){
                $("input[name='hosrSelfprice'][value='1']").attr("checked","checked");
            }else {
                $("input[name='hosrSelfprice'][value='0']").attr("checked","checked");
            }
        }

        function sexXian(data){
            //性别数据回显
            if (data==1){
                $("input[name='dSex'][value='1']").attr({"checked":"checked"})
            }else {
                $("input[name='dSex'][value='2']").attr({"checked":"checked"})
            }
        }

        //保存
        function baocun() {
            let hosrIdcar = $("#hosrIdcar").text();
            let hosrId = $("input[name='hosrId']").val();
            let behNursepeople = $("input[name='behNursepeople']").val();
            let behPatbed = $("input[name='behPatbed']").val();
            let behAntecedent = $("input[name='behAntecedent']").val();
            let behIllness = $("#behIllness").val();

            //参数校验
            if (hosrId == '') {
                alert("挂号id为空");
                return;
            }
            if (behNursepeople == '') {
                alert("护理为空");
                return;
            }
            if (behPatbed == '') {
                alert("床位号为空");
                return;
            }
            if (behAntecedent == '') {
                alert("缴费押金为空");
                return;
            }else if (isNaN(behAntecedent)){
                alert("缴费押金，请输入数字");
                return;
            }
            if (behIllness == '') {
                alert("病情为空");
                return;
            }

            console.log(hosrId)
            //发送ajax请求
            $.ajax({
                url: "addBeHospital",
                data: {
                    'behId': hosrId,
                    'behNursepeople': behNursepeople,
                    'behPatbed': behPatbed,
                    'behAntecedent': behAntecedent,
                    'behIllness': behIllness
                },
                type: 'POST',
                dataType: 'json',
                success: function (response) {
                    if (response.response.flag) {
                        window.location.href = "index.html";
                    } else {
                        alert("添加失败，请重试！");
                    }
                }
            })
        }

        //根据科室获取医生信息
        function getDoctor(){
            let keshi = $("#keShi").val();
            $.ajax({
                url: "http://localhost:8080/doctor/selectDoctorByKeshi",
                data: {'keshi': keshi},
                type: 'get',
                dataType: 'json',
                success: function (response) {
                    let list = response.data.doctors;
                    if (response.response.flag) {
                        //情况下级标签
                        $("#doctorName").empty();
                        //医生列表
                        $.each(list,function (index,item){
                            $("#doctorName").append("" +
                                "<option name=\""+item.dName+"\">"+item.dName+"</option>")
                        });
                    } else {
                        console.log("查询失败，请重试！");
                    }
                }
            })
        }
    </script>
</head>
<body>
<form action="../../index.html" method="post" class="definewidth m20">
    <table class="table table-bordered table-hover definewidth m10">
        <tr>
            <td width="10%" class="tableleft">病历号</td>
            <td><input type="text" name="hosrId" onchange="getMsg()" placeholder="输入病历号回车自动带出挂号人信息"/></td>
            <span style="color: red"></span>
        </tr>
        <tr>
            <td width="10%" class="tableleft">姓名</td>
            <td id="hosrName"></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">证件类型</td>
            <td>身份证</td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">证件号</td>
            <td id="hosrIdcar"></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">社保号</td>
            <td id="hosrMedical"></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">联系电话</td>
            <td id="hosrPhone"></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">是否自费</td>
            <td>
                <input disabled type="radio" name="hosrSelfprice" value="1" checked/>否&nbsp;&nbsp;&nbsp;
                <input disabled type="radio" name="hosrSelfprice" value="0"/>是
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">性别</td>
            <td><input disabled type="radio" name="hosrSex" value="1" checked/>男&nbsp;&nbsp;&nbsp;
                <input disabled type="radio" name="hosrSex" value="2"/>女
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">年龄</td>
            <td id="hosrAge"></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">初复诊</td>
            <td><input disabled type="radio" name="hosrLookdoctor" value="0" checked/>初诊&nbsp;&nbsp;&nbsp;
                <input disabled type="radio" name="hosrLookdoctor" value="1"/>复诊
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">所挂科室</td>
            <td><select id="keShi" disabled name="keShi">
                <option value="急诊科">急诊科</option>
                <option value="骨科">骨科</option>
                <option value="血液科">血液科</option>
            </select></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">指定医生</td>
            <td>
                <select disabled id="doctorName" name="doctorName">

                </select>
            </td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">备注</td>
            <td id="hosrRemark"></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">护理</td>
            <td><input type="text" name="behNursepeople" value=""/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">床位号</td>
            <td><input type="text" name="behPatbed" value=""/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">缴费押金</td>
            <td><input type="text" name="behAntecedent" value=""/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">病情</td>
            <td><textarea id="behIllness"></textarea></td>
        </tr>
        <tr>
            <td colspan="2">
                <center>
                    <input class="btn btn-primary" type="button" onclick="baocun()" value="保存"/> &nbsp;&nbsp;
                    <input type="button" class="btn btn-success" name="backid" id="backid" value="返回列表"/>
                </center>
            </td>
        </tr>
    </table>
</form>
</body>
</html>